package org.phalanx.server.game;

import java.util.ArrayList;
import java.util.Iterator;

import org.phalanx.server.ServerCache.Cacheable;

public class GameMoveQueue implements Cacheable {
	private Integer gameId;
	private ArrayList<GameMove> gameMoveList;
	
	public static final Integer ATTACK = 0;
	public static final Integer ATTRIBUTES = 1;
	public static final Integer TRAVEL = 2;
	public static final Integer BUILD = 3;
	
	public GameMoveQueue(Integer gameId){
		this.setId(gameId);
		gameMoveList = new ArrayList<GameMove>();
	}
	
	@Override
	public Integer getId() {
		// TODO Auto-generated method stub
		return gameId;
	}

	@Override
	public void setId(Integer id) {
		gameId = id;
	}
	
	public ArrayList<GameMove> getMoveList(){
		return gameMoveList;
	}
	
	public ArrayList<GameMove> getMoveList(Integer turn){
		ArrayList<GameMove> movesByTurn = new ArrayList<GameMove>();
		
		Iterator<GameMove> e = gameMoveList.iterator();
		
		while(e.hasNext()){
			GameMove gMove = e.next();
			
			if (gMove.getTurn().equals(turn)){
				movesByTurn.add(gMove);
			}
		}
		
		return movesByTurn;
	}
	
	public void addMove(GameMove gMove){
		if (!gameMoveList.contains(gMove)){
			gameMoveList.add(gMove);
		}
	}
	
	public void removeMove(GameMove gMove){
		if (gameMoveList.contains(gMove)){
			gameMoveList.remove(gMove);
		}
	}
	
	public ArrayList<GameMove> getMoveByAttackType(Integer turnId, Integer actionType){
		ArrayList<GameMove> actionMoves = new ArrayList<GameMove>();
		
		Iterator<GameMove> i = getMoveList(turnId).iterator();
		
		while (i.hasNext()){
			GameMove oneMove = i.next();
			
			if (oneMove.getActionType().equals(actionType)){
				actionMoves.add(oneMove);
			}
		}
		
		return actionMoves;
	}
}
